﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Srvtools;
using System.Collections;
using System.Text;

public partial class WorkTimeN_ViewWorkOn2Pay : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;
    private StringBuilder sbrCloseId;
    private StringBuilder sbrCloseDetail;

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WorkTimeN_ViewWorkOn2Pay));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // wsViewDepWorkOnCheck
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = "5abc890f-29be-408a-bb92-77dcb8bb9319";
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = -1;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "Common.InfoInti";
        this.WMaster.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();
    }

    private void Bind()
    {
        if (DlCloseAccount.Items.Count > 0)
        {
            return;
        }

        DataTable dt = wdsCloseAccount.View.Table;
        foreach (DataRow dr in dt.Rows)
        {
            if (dr["Pdate"].ToString() != "")
            {
                DlCloseAccount.Items.Add(dr["Pdate"].ToString());
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        



        MasterPage_MasterPage mpg = (MasterPage_MasterPage)this.Page.Master;
        mpg.HelpHref = "~/Help/WorkTime/查看员工计算工资的考勤数据.htm";
        mpg.PageName = "查看员工计算工资的考勤数据";
        mpg.PicUrl = "";
        mpg.IntiBar();

        if (Page.IsPostBack == false)
        {
            Bind();
            close.Visible = false;
        }
    }

    protected void Refresh_Click(object sender, EventArgs e)
    {
        if (DepartmentDList1.SelectDepmanetId == "0" || DepartmentDList1.SelectDepmanetId == "")
        {
            ClientScript.RegisterStartupScript(GetType(), "MSG", "alert('请选择部门')", true);
            return;
        }
        string strDep = DepartmentDList1.SelectDepmanetId;
        GetEmps(strDep, 1, Convert.ToInt32(Scount.SelectedValue), Ename.Text.Trim(),ddlStatus.SelectedValue);
        apg.CurrentPageIndex = 1;

    }

    private void GetEmps(string SelDepId, int page, int scount, string En,string Status)
    {
        InitializeComponent();
        sbrCloseId = new StringBuilder();
        sbrCloseDetail = new StringBuilder();
        //get the WorkOn data
        int num = scount;
        int count = 0;
        DataSet EmpList;
        string sSql;

        //行数
        sSql = "select count(Employees.EmployeeID) FROM  Employees INNER JOIN Department ON Employees.DepartmentId = Department.DepartmentId" +
            " WHERE (Employees.DepartmentId LIKE '" + SelDepId + "%') " + (En != "" ? " AND Employees.EmpName like ('%" + En + "%')" : "") + (Status != "-1" ? " And EmpStatus=" + Status : "");
        EmpList = WMaster.Execute(sSql);
        count = Convert.ToInt32(EmpList.Tables[0].Rows[0][0]);
        apg.RecordCount = count;
        apg.PageSize = num;


        //分页
        int index = 0;
        if (count == 0)
        {
            return;
        }
        if (page >= 1)
        {
            index = count - (page - 1) * num;
            if (index <= 0)
            {
                index = count % num;
            }
        }
        sSql = "select top " + num + " Employees.EmployeeID, Employees.EmpName, Department.DepartmentName from  Employees INNER JOIN Department ON Employees.DepartmentId = Department.DepartmentId " +
                            "where (EmployeeID>=(select min(EmployeeID) from " +
                            "(select top " + index + " EmployeeID from Employees INNER JOIN Department ON Employees.DepartmentId = Department.DepartmentId " +
                            "where (Employees.DepartmentId LIKE '" + SelDepId + "%') " + (En != "" ? " AND Employees.EmpName like ('%" + En + "%')" : "") + (Status != "-1" ? " And EmpStatus=" + Status : "") +
                            " order by Employees.EmployeeID desc) as t)) and (Employees.DepartmentId LIKE '" + SelDepId + "%')  " + (En != "" ? " AND Employees.EmpName like ('%" + En + "%')" : "") + (Status != "-1" ? " And EmpStatus=" + Status : "") +
                            " order by Employees.EmployeeID asc";

        EmpList = WMaster.Execute(sSql);

        Rpt.DataSource = EmpList;
        Rpt.DataBind();

        if (sbrCloseId.ToString().Length > 0)
        {
            close.Visible = true;
            string cid = sbrCloseId.ToString().Substring(0, sbrCloseId.ToString().Length - 1);
            string dd = sbrCloseDetail.ToString();

            LinkButton1.Attributes.Add("onclick", "return confirm('是否关帐?\\r\\r确认以下员工的关帐信息：\\r\\r" + dd + "')");
            LinkButton1.CommandArgument = cid;
        }
        else
        {
            close.Visible = false;
        }


    }

    protected void Rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            DataRowView drv = (DataRowView)e.Item.DataItem;
            Literal kqms = (Literal)e.Item.FindControl("kqms");
            string EmpId = drv["EmployeeId"].ToString();
            string STime = DlCloseAccount.SelectedValue != "-1" ? DlCloseAccount.SelectedValue : DateTime.Now.ToString("yyyy-MM");
            DateTime st = Convert.ToDateTime(STime + "-01");
            DateTime et = st.AddMonths(1).AddDays(-1);
            bool hasClose = false;

            #region GetWorkData Init
            Hashtable WorkTime = new Hashtable();
            DataTable WorkAddUp = new DataTable();
            Hashtable WorkHoliday = new Hashtable();
            DataTable WorkOverTime = new DataTable();
            DataTable IsGoingWorkFlowSalary = new DataTable();
            //考勤
            bool IsDayWork = false; //是否常日班
            DataTable SpecialWorkTime = null;
            string StartWorkOn = "";
            string EndWorkOn = "";
            string LateOfStartTime = "";
            string LeaveOfEndTime = "";
            #endregion

            #region GetWorkData string
            //获取当月上班时间
            object[] WorkTimeObj = WorkOnTime(EmpId, st, et);

            //考勤类型
            object[] WorkTypeObj = WorkOnType(EmpId);

            //获取ADDUP
            object[] WorkAddUpObj = WorkOnAddUp(EmpId, (DlCloseAccount.SelectedValue != "-1" ? STime : null), et);

            //获取节假日
            object[] WorkHolidayObj = WorkOnHoliday(EmpId, (DlCloseAccount.SelectedValue != "-1" ? STime : null), st, et);

            //筛选加班
            object[] WorkOverTimeObj = WorkOnOverTime(EmpId, (DlCloseAccount.SelectedValue != "-1" ? STime : null), et);

            //未结束工作流 薪资有关
            object[] IsGoingWorkFlowSalaryObj = WorkOnSalaryFlow(EmpId, st, et);
            #endregion

            #region GetWorkOnData

            object[] WorkOnData = GetWorkOnData(WorkTimeObj, WorkTypeObj, WorkAddUpObj, WorkOverTimeObj, WorkHolidayObj, IsGoingWorkFlowSalaryObj);

            WorkTime = WorkOnData[0] as Hashtable;

            //type 
            object[] wt = WorkOnData[1] as object[];
            IsDayWork = (bool)wt[0];
            SpecialWorkTime = (DataTable)wt[1];
            StartWorkOn = wt[2].ToString();
            EndWorkOn = wt[3].ToString();
            LateOfStartTime = wt[4].ToString();
            LeaveOfEndTime = wt[5].ToString();

            WorkAddUp = WorkOnData[2] as DataTable;
            WorkHoliday = WorkOnData[4] as Hashtable;
            WorkOverTime = WorkOnData[3] as DataTable;
            IsGoingWorkFlowSalary = WorkOnData[5] as DataTable;

            #endregion

            #region 计算上下班考勤
            string Daykey = "";
            DateTime tempst = st;
            Hashtable WorkDayHour = new Hashtable();

            while (tempst <= et)
            {
                Daykey = tempst.Year.ToString().Trim() + "-" + tempst.Month.ToString().Trim() + "-" + tempst.Day.ToString().Trim();
                string DKey = Daykey;
                Single DayCC;
                bool NowIsWorkingDay = IsWorkingDay(tempst, out  DayCC, WorkHoliday);

                double dwh = 0;

                if (WorkTime.Count > 0 && (SpecialWorkTime != null || StartWorkOn != ""))
                {
                    if (IsDayWork)
                    {
                        object a = WorkTime[DKey];
                        dwh = DayWorkHours((DateTime[])WorkTime[DKey], LateOfStartTime, EndWorkOn);
                    }
                    else
                    {
                        dwh = SpecialWorkHours((DateTime[])WorkTime[DKey], (DateTime[])WorkTime[EmpId + "-" + Convert.ToDateTime(Daykey).AddDays(1).ToString("yyyy-M-d")], SpecialWorkTime);
                    }
                }

                if (NowIsWorkingDay)
                {
                    dwh = 8 - dwh;
                    if (dwh > 0)
                    {
                        DataRow[] drs = WorkAddUp.Select("Wyear=" + tempst.Year + " and Wmonth=" + tempst.Month + " and Wday=" + tempst.Day + " and EmployeeId=" + EmpId + " and Wtype <> 15");
                        double dwhs = 0;
                        foreach (DataRow dr in drs)
                        {
                            dwhs += Convert.ToDouble(dr["WaddHour"]);
                            //EmpAddUp
                        }
                        dwh = dwh - dwhs;
                    }
                    if (dwh > 0)
                    {
                        kqms.Text += "<span style='width:100px'> <span style='color:red'>" + tempst.ToString("yyyy-MM-dd") + " </span> 缺考勤记录 " + (dwh > 8 ? 8 : dwh).ToString("#.##") + "小时</span> <br/>";
                    }
                }
                else
                {
                    if (dwh > 0)
                    {
                        kqms.Text += "<span style='width:100px'> <span style='color:green'>" + tempst.ToString("yyyy-MM-dd") + "  [" +
                            (tempst.DayOfWeek == DayOfWeek.Saturday ? "周六" : "周日") + "] 有打卡记录 </span> " + dwh.ToString("#.##") + "小时</span> <br/>";
                    }
                }

                tempst = tempst.AddDays(1);
            }
            #endregion

            #region 请假计算
            string qj1 = "";//未关
            string qj2 = "";

            Literal qj = (Literal)e.Item.FindControl("qj");
            if (WorkAddUp != null)
            {
                DataRow[] drWorkOn = WorkAddUp.Select("BLeave=1 and IsSalaryLeave=0");
                for (int i = 0; i < drWorkOn.Length; i++)
                {
                    DataRow dr = drWorkOn[i];
                    string TPName = dr["LeaveTypeName"].ToString();
                    if (Convert.IsDBNull(dr["Pdate"]) || dr["Pdate"].ToString() == "")
                    {
                        qj1 += " <span style='color:red'>" + dr["Wyear"].ToString() + "-" + dr["Wmonth"].ToString() + "-" + dr["Wday"].ToString() + " </span>" + TPName + dr["WaddHour"].ToString() + "小时 <br/>";
                        hasClose = true;
                    }
                    else
                    {
                        qj2 += " <span style='color:red'>" + dr["Wyear"].ToString() + "-" + dr["Wmonth"].ToString() + "-" + dr["Wday"].ToString() + " </span>" + TPName + dr["WaddHour"].ToString() + "小时 <br/>";
                    }
                }
                qj.Text = "已关帐:<br/>" + qj2 + "<br/><br/><br/>未关帐:<br/>" + qj1;
            }
            #endregion

            #region 加班计算
            DataRow[] drOverTime = WorkOverTime.Select("Repay='2'");
            Literal rcjb = (Literal)e.Item.FindControl("rcjb");
            Literal sxrjb = (Literal)e.Item.FindControl("sxrjb");
            Literal jjrjb = (Literal)e.Item.FindControl("jjrjb");
            Literal syjbscxs = (Literal)e.Item.FindControl("syjbscxs");

            string Divtcjb = "";
            string Divsxrjb = "";
            string Divjjrjb = "";

            string CDivtcjb = "";
            string CDivsxrjb = "";
            string CDivjjrjb = "";

            Single OverTimeG = 0; //日常加班
            Single OverTimeV = 0; //双修日加班
            Single OverTimeH = 0; //节假日加班
            Single AllOverTimeD = 0;//所有加班乘系数值

            Single OverTimeGG = 0; //日常加班
            Single OverTimeVV = 0; //双修日加班
            Single OverTimeHH = 0; //节假日加班
            Single AllOverTimeDD = 0;//所有加班乘系数值

            foreach (DataRow dr in drOverTime)
            {
                Single DayCC;
                DateTime td = Convert.ToDateTime(dr["Wyear"].ToString() + "-" + dr["Wmonth"].ToString() + "-" + dr["Wday"].ToString());

                bool NowIsWorkingDay = IsWorkingDay(td, out  DayCC, WorkHoliday);

                Single OverTimeHours = Convert.ToSingle(dr["Waddhour"]);

                if (Convert.IsDBNull(dr["Pdate"]) || dr["Pdate"].ToString() == "")
                {
                    switch (Convert.ToInt32(DayCC * 10))
                    {
                        case 20:
                            OverTimeVV = OverTimeVV + OverTimeHours;
                            AllOverTimeDD = AllOverTimeDD + DayCC * OverTimeHours;

                            Divsxrjb += td.ToString("yyyy-MM-dd") + " [" + OverTimeHours + "小时]<br/>";
                            break;
                        case 30:
                            OverTimeHH = OverTimeHH + OverTimeHours;
                            AllOverTimeDD = AllOverTimeDD + DayCC * OverTimeHours;

                            Divjjrjb += td.ToString("yyyy-MM-dd") + " [" + OverTimeHours + "小时]<br/>";
                            break;
                        default:
                            OverTimeGG = OverTimeGG + OverTimeHours;
                            AllOverTimeDD = AllOverTimeDD + DayCC * OverTimeHours;

                            Divtcjb += td.ToString("yyyy-MM-dd") + " [" + OverTimeHours + "小时]<br/>";
                            break;
                    }

                    //记录加班关帐Id
                    sbrCloseId.Append(dr["id"].ToString() + ",");
                }
                else
                {
                    switch (Convert.ToInt32(DayCC * 10))
                    {
                        case 20:
                            OverTimeV = OverTimeV + OverTimeHours;
                            AllOverTimeD = AllOverTimeD + DayCC * OverTimeHours;

                            CDivsxrjb += td.ToString("yyyy-MM-dd") + " [" + OverTimeHours + "小时]<br/>";
                            break;
                        case 30:
                            OverTimeH = OverTimeH + OverTimeHours;
                            AllOverTimeD = AllOverTimeD + DayCC * OverTimeHours;

                            CDivjjrjb += td.ToString("yyyy-MM-dd") + " [" + OverTimeHours + "小时]<br/>";
                            break;
                        default:
                            OverTimeG = OverTimeG + OverTimeHours;
                            AllOverTimeD = AllOverTimeD + DayCC * OverTimeHours;

                            CDivtcjb += td.ToString("yyyy-MM-dd") + " [" + OverTimeHours + "小时]<br/>";
                            break;
                    }
                }
            }
            #endregion

            //记录加班关帐信息
            if (OverTimeGG != 0 || OverTimeVV != 0 || OverTimeHH != 0)
            {
                hasClose = true;
            }

            rcjb.Text = "<div class=\"link\" style='z-index:40'><span onmouseover=\"display('" + EmpId + "rcjb')\" onmouseout=\"disappear('" + EmpId + "rcjb')\" class='lk'>" + OverTimeG.ToString() + " [日常 已关帐]</span><div class='box' id='" + EmpId + "rcjb'>日常加班已关帐<br/>" + CDivtcjb + "</div></div>" +
                  "<div class=\"link\" style='z-index:40'><span onmouseover=\"display('" + EmpId + "crcjb')\" onmouseout=\"disappear('" + EmpId + "crcjb')\" class='lk'><span style='color:red'>" + OverTimeGG.ToString() + "</span> [日常 未关帐]<div class='box' id='" + EmpId + "crcjb'>日常加班未关帐<br/>" + Divtcjb + "</div></div>";

            sxrjb.Text = "<div class=\"link\"  style='z-index:30'><span onmouseover=\"display('" + EmpId + "sxrjb')\" onmouseout=\"disappear('" + EmpId + "sxrjb')\" class='lk'>" + OverTimeV.ToString() + " [双修日 已关帐]</span><div class='box' id='" + EmpId + "sxrjb'>双修日加班已关帐<br/>" + CDivsxrjb + "</div></div>" +
                  "<div class=\"link\" style='z-index:30'><span onmouseover=\"display('" + EmpId + "csxrjb')\" onmouseout=\"disappear('" + EmpId + "csxrjb')\" class='lk'><span style='color:red'>" + OverTimeVV.ToString() + "</span> [双修日 未关帐]<div class='box' id='" + EmpId + "csxrjb'>双修日加班未关帐<br/>" + Divsxrjb + "</div></div>";


            jjrjb.Text = "<div class=\"link\"  style='z-index:20'><span onmouseover=\"display('" + EmpId + "jjrjb')\" onmouseout=\"disappear('" + EmpId + "jjrjb')\" class='lk'>" + OverTimeH.ToString() + " [节假日 已关帐]</span><div class='box' id='" + EmpId + "jjrjb'>节假日加班已关帐<br/>" + CDivjjrjb + "</div></div>" +
                  "<div class=\"link\" style='z-index:20'><span onmouseover=\"display('" + EmpId + "cjjrjb')\" onmouseout=\"disappear('" + EmpId + "cjjrjb')\" class='lk'><span style='color:red'>" + OverTimeHH.ToString() + "</span> [节假日 未关帐]<div class='box' id='" + EmpId + "cjjrjb'>节假日加班未关帐<br/>" + Divjjrjb + "</div></div>";

            syjbscxs.Text = AllOverTimeD.ToString() + "[已关]&nbsp;&nbsp;&nbsp;&nbsp;<span style='color:red'>" + AllOverTimeDD.ToString() + "</span>[未关]";

            //记录所有关帐ID
            if (WorkAddUp != null)
            {
                DataRow[] drClose = WorkAddUp.Select(" Pdate='' or Pdate is null");
                foreach (DataRow dr in drClose)
                {
                    sbrCloseId.Append(dr["id"].ToString() + ",");
                }
            }


            //未结束工作流
            Literal wjslc = (Literal)e.Item.FindControl("wjslc");
            if (IsGoingWorkFlowSalary != null)
            {
                foreach (DataRow dr in IsGoingWorkFlowSalary.Rows)
                {
                    wjslc.Text += " <a href='javascript:void(0)' onclick='WinOpen(\"" + dr["url"].ToString() + dr["lid"].ToString() + "\")'> " + dr["lname"].ToString() + " 编号:" + dr["lid"].ToString() + "</a><br/>";
                }
            }

            if (hasClose)
            {
                if (sbrCloseDetail.Length > 15)
                {
                    sbrCloseDetail.Append("\\r" + drv["EmpName"].ToString() + "\\t");
                }
                else
                {
                    sbrCloseDetail.Append(drv["EmpName"].ToString() + "\\t");
                }
            }
        }
    }

    protected void apg_PageChanged(object sender, EventArgs e)
    {
        string SelDepId = DepartmentDList1.SelectDepmanetId;
        if (SelDepId.Length > 0 && SelDepId != "0")
        {
            GetEmps(SelDepId, apg.CurrentPageIndex, Convert.ToInt32(Scount.SelectedValue), Ename.Text.Trim(), ddlStatus.SelectedValue);
        }
        else
        {
            string message = "请首先选择部门!";
            //this.Page.Response.Write("<script>alert(\"" + message + "\");</script>");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert(\"" + message + "\");", true);
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        object[] obj = new object[2] { LinkButton1.CommandArgument.ToString(), DlCloseAccount.SelectedValue };
        object[] myRet2 = CliUtils.CallMethod("SWorkTime", "CloseAccount", obj);

        if (Convert.ToInt32(myRet2[1]) > 0)
        {
            ClientScript.RegisterStartupScript(GetType(), "", "ymPrompt.alert({message:'关帐成功！',title:'操作信息提示',winPos:'rb',showMask:false,slideCfg:{increment:0.3,interval:50}});setTimeout(function(){ymPrompt.close()},1500);", true);
            apg_PageChanged(null, null);
        }
    }

    #region get data

    /// <summary>
    /// get
    /// </summary>
    public object[] GetWorkOnData(object[] WorkOnTime, object[] WorkOnType, object[] WorkOnAddUp, object[] WorkOnOverTime, object[] WorkOnHoliday, object[] WorkOnSalaryFlow)
    {
        object[] myRet = CliUtils.CallMethod("SWorkTime", "GetWorkOnSalaryData", new object[] { WorkOnTime, WorkOnType, WorkOnAddUp, WorkOnOverTime, WorkOnHoliday, WorkOnSalaryFlow });
        if (myRet[1] != null)
        {
            object[] mb = myRet[1] as object[];

            //1
            Hashtable d1 = mb[0] as Hashtable;

            //2
            object[] mb2 = mb[1] as object[];
            bool IsDayWork = false;
            DataTable SpecialWorkTime = null;
            string StartWorkOn = "";
            string EndWorkOn = "";
            string LateOfStartTime = "";
            string LeaveOfEndTime = "";
            try
            {
                if (mb2 != null)
                {
                    if (mb2[0].ToString() == "N")
                    {
                        if (((DataSet)mb2[1]).Tables[0] != null && ((DataSet)mb2[1]).Tables[0].Rows.Count > 0)
                        {
                            DataRow dr = ((DataSet)mb2[1]).Tables[0].Rows[0];
                            StartWorkOn = dr["st"].ToString();
                            EndWorkOn = dr["et"].ToString();
                            LateOfStartTime = dr["sct"].ToString();
                            LeaveOfEndTime = dr["ect"].ToString();
                        }
                        IsDayWork = true;
                    }
                    else
                    {
                        IsDayWork = false;
                        SpecialWorkTime = ((DataSet)mb2[1]).Tables[0];
                    }
                }
            }
            catch
            {
                IsDayWork = false;
                SpecialWorkTime = null;
            }
            object[] d2 = new object[] { IsDayWork, SpecialWorkTime, StartWorkOn, EndWorkOn, LateOfStartTime, LeaveOfEndTime };

            //3
            DataSet mb3 = mb[2] as DataSet;
            DataTable dt3 = new DataTable();
            if (mb3 != null)
            {
                dt3 = ((DataSet)mb3).Tables[0];
            }

            //4
            DataSet mb4 = mb[3] as DataSet;
            DataTable dt4 = new DataTable();
            if (mb4 != null)
            {
                dt4 = ((DataSet)mb4).Tables[0];
            }

            //5
            Hashtable d5 = mb[4] as Hashtable;

            //6
            DataSet mb6 = mb[5] as DataSet;
            DataTable dt6 = new DataTable();
            if (mb6 != null)
            {
                dt6 = ((DataSet)mb6).Tables[0];
            }

            return new object[] { d1, d2, dt3, dt4, d5, dt6 };
        }
        else
        {
            return null;
        }

    }

    /// <summary>
    /// 本月考勤记录
    /// </summary>
    private object[] WorkOnTime(string EmpId, DateTime st, DateTime et)
    {
        object[] objParam = new object[3];
        objParam[0] = EmpId;
        objParam[1] = st.ToString("yyyy-MM-dd 00:00:00");
        objParam[2] = et.AddDays(1).ToString("yyyy-MM-dd");
        return objParam;
    }

    /// <summary>
    /// 考勤类型
    /// </summary>
    private object[] WorkOnType(string EmpId)
    {
        return new object[] { " WorkTime_WorkOnTypeGroup.EmployeeId=" + EmpId };
    }

    /// <summary>
    /// 获取考勤汇总
    /// </summary>
    private object[] WorkOnAddUp(string EmpId, string Pdate, DateTime et)
    {
        object[] objParam3 = new object[1];
        objParam3[0] = " 1=1 and ((Pdate='' or Pdate is null) or Pdate='" + Pdate + "')" +
            " and cast(cast(Wyear as varchar(4))+'-'+cast(Wmonth as varchar(2))+'-'+cast(Wday as varchar(2))as datetime) <='" + et + "' and WorkTime_AddUp.EmployeeId=" + EmpId;
        return objParam3;
    }

    /// <summary>
    /// 获取加班
    /// </summary>
    private object[] WorkOnOverTime(string EmpId, string Pdate, DateTime et)
    {
        object[] objParam3 = new object[1];
        objParam3[0] = "1=1 and ((Pdate='' or Pdate is null) or Pdate='" + Pdate + "')" +
            " and cast(cast(Wyear as varchar(4))+'-'+cast(Wmonth as varchar(2))+'-'+cast(Wday as varchar(2))as datetime) <='" + et + "' and WorkTime_AddUp.EmployeeId=" + EmpId + " and Wtype='15'";
        return objParam3;
    }

    /// <summary>
    /// 获取考勤节假日
    /// </summary>
    private object[] WorkOnHoliday(string EmpId, string Pdate, DateTime st, DateTime et)
    {
        //本月节假日
        object[] objParam2 = new object[3];
        objParam2[0] = st.ToString("yyyy-MM-dd 00:00:00");
        objParam2[1] = et.ToString("yyyy-MM-dd 23:59:59");

        objParam2[2] = " 1=1 and ((Pdate='' or Pdate is null) or Pdate='" + Pdate + "')" +
            " and cast(cast(Wyear as varchar(4))+'-'+cast(Wmonth as varchar(2))+'-'+cast(Wday as varchar(2))as datetime) <='" + et + "' and WorkTime_AddUp.EmployeeId=" + EmpId;
        return objParam2;

    }

    /// <summary>
    /// 未结束工作流 薪资有关
    /// </summary>
    private object[] WorkOnSalaryFlow(string EmpId, DateTime st, DateTime et)
    {
        object[] objParam3 = new object[3];
        objParam3[0] = st;
        objParam3[1] = et;
        objParam3[2] = EmpId;

        return objParam3;
    }

    #endregion

    #region 计算时间

    /// <summary>
    /// 判断是否为工作日
    /// </summary>
    /// <param name="Inday"></param>
    /// <returns></returns>
    private bool IsWorkingDay(DateTime Inday, out Single DayCC, Hashtable CompWorkDateDefine)
    {
        int DatePeptry;
        string DKey = Inday.Year.ToString().Trim() + "-" + Inday.Month.ToString().Trim() + "-" + Inday.Day.ToString().Trim();
        DayCC = 1.5f;

        if (Inday.DayOfWeek == DayOfWeek.Saturday || Inday.DayOfWeek == DayOfWeek.Sunday)
        {
            if (CompWorkDateDefine.ContainsKey(DKey) == false)
            {
                DatePeptry = 0;
                DayCC = 2.0f;// = "双休日";
                return false;
            }
            else
            {
                object[] DtIn = (object[])CompWorkDateDefine[DKey];
                bool Dbk = (bool)DtIn[0];
                DatePeptry = (int)DtIn[1];

                switch (DatePeptry)
                {
                    case 1:
                        DayCC = 1.5f;// "工作日";
                        break;
                    case 2:
                        DayCC = 3.0f;// "法定假日";
                        break;
                    case 3:
                        DayCC = 1.5f;//;
                        break;
                    default:
                        DayCC = 1.5f;//;
                        break;
                }

                return Dbk;
            }
        }
        else
        {
            if (CompWorkDateDefine.ContainsKey(DKey) == false)
            {
                DatePeptry = 0;
                DayCC = 1.5f;// "工作日";
                return true;
            }
            else
            {
                object[] DtIn = (object[])CompWorkDateDefine[DKey];
                bool Dbk = (bool)DtIn[0];
                DatePeptry = (int)DtIn[1];
                switch (DatePeptry)
                {
                    case 1:
                        DayCC = 1.5f;// "工作日";
                        break;
                    case 2:
                        DayCC = 3.0f;// "法定假日";
                        break;
                    case 3:
                        DayCC = 2.0f;// "休息日";
                        break;
                    default:
                        DayCC = 1.5f;//;
                        break;
                }
                return Dbk;
            }
        }

    }

    private double DayWorkHours(DateTime[] DtIn, string LateOfStartTime, string EndWorkOn)
    {
        if (DtIn == null)
        {
            return 0;
        }
        else
        {
            DateTime cutWs = Convert.ToDateTime(DtIn[0].ToString("yyyy-MM-dd") + " " + LateOfStartTime + ":00");
            DateTime cutWe = Convert.ToDateTime(DtIn[0].ToString("yyyy-MM-dd") + " " + EndWorkOn + ":00");
            return WorkHours(DtIn, cutWs, cutWe);
        }
        //return LackHours =0= 8 ? 8 : LackHours;
        //return Convert.ToInt32(Math.Ceiling(eet.Subtract(sst).TotalHours)) >= 8;
    }

    private double SpecialWorkHours(DateTime[] DtInToday, DateTime[] DtInTomorrow, DataTable SpecialWorkTime)
    {
        //考勤相差小于10 正确考勤记录
        DateTime[] dts = new DateTime[2];
        if (DtInToday == null)
        {
            return 0;
        }
        DateTime sst = DtInToday[0];
        DateTime eet = DtInToday[1];
        double ct = eet.Subtract(sst).TotalHours;
        if (ct <= 10 && ct != 0)
        {
            dts[0] = sst;
            dts[1] = eet;
        }
        else
        {
            if (DtInTomorrow == null)
            {
                return 0;
            }
            sst = DtInToday[1];
            eet = DtInTomorrow[0];
            ct = eet.Subtract(sst).TotalHours;
            if (ct <= 10 && ct != 0)
            {
                dts[0] = sst;
                dts[1] = eet;
            }
        }

        //套上班时间
        foreach (DataRow dr in SpecialWorkTime.Rows)
        {
            DateTime st = new DateTime();
            DateTime et = new DateTime();

            //套上班时间相同
            st = Convert.ToDateTime(dts[0].ToString("yyyy-MM-dd") + " " + dr["st"] + ":00");
            et = Convert.ToDateTime(dts[0].ToString("yyyy-MM-dd") + " " + dr["sct"] + ":00");
            if (dts[0].CompareTo(st) >= 0 & dts[0].CompareTo(et) <= 0)
            {
                return WorkHours(dts, Convert.ToDateTime(dts[0].ToString("yyyy-MM-dd") + " " + dr["sct"] + ":00"),
                    Convert.ToDateTime(dts[1].ToString("yyyy-MM-dd") + " " + dr["et"].ToString() + ":00"));
            }

            //套下班时间相同
            st = Convert.ToDateTime(dts[1].ToString("yyyy-MM-dd") + " " + dr["ect"] + ":00");
            et = Convert.ToDateTime(dts[1].ToString("yyyy-MM-dd") + " " + dr["et"] + ":00");
            if (dts[1].CompareTo(st) >= 0 & dts[1].CompareTo(et) <= 0)
            {
                return WorkHours(dts, Convert.ToDateTime(dts[0].ToString("yyyy-MM-dd") + " " + dr["sct"] + ":00"),
                    Convert.ToDateTime(dts[1].ToString("yyyy-MM-dd") + " " + dr["et"].ToString() + ":00"));
            }
        }
        if (DtInToday[0] != null)
        {
            return -1;
        }
        else
        {
            return 0;
        }
    }

    /// <summary>
    /// 获取考勤时间
    /// </summary>
    /// <param name="DtIn">考勤时间 早晚</param>
    /// <param name="cutWs">考勤规定最晚上班时间</param>
    /// <param name="cutWe">考勤规定最早下班时间</param>
    /// <returns></returns>
    private double WorkHours(DateTime[] DtIn, DateTime cutWs, DateTime cutWe)
    {
        DateTime sst = DtIn[0];
        DateTime eet = DtIn[1];

        double LackHours = 0;
        LackHours += sst.Subtract(cutWs).TotalHours >= 0 ? sst.Subtract(cutWs).TotalHours : 0;
        LackHours += eet.Subtract(cutWe).TotalHours >= 0 ? 0 : cutWe.Subtract(eet).TotalHours;

        if (LackHours == 0)
        {
            return 8;
        }
        else
        {
            return Math.Round(8 - LackHours, 1);
        }
    }

    #endregion

}
